package com.econ.powercloud.ems.observer;

import com.econ.powercloud.ems.common.interf.ProtectSoeDataObserver;
import com.econ.powercloud.ems.common.pojo.EmsKafkaEvenDataDTO;
import com.econ.powercloud.ems.config.EMSStaticMap;
import com.econ.powercloud.ems.constant.SysConstant;
import com.econ.powercloud.ems.dal.entity.EmsDevice;
import com.econ.powercloud.ems.dal.entity.EmsProtectSoePidConfig;
import com.econ.powercloud.ems.service.biz.ProtectAndSoeEventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author : zjf
 * @Description : 判断事件是否是保护/SOE事件
 * @Date : 2022/10/31 16:25
 * @Modified by : zjf
 */
@Component
public class ProtectSoeEventDealProcessor implements ProtectSoeDataObserver {
    @Autowired
    private ProtectAndSoeEventService protectAndSoeEventService;

    @Override
    public void doInvoke(EmsKafkaEvenDataDTO data) {
        EmsDevice emsDevice = EMSStaticMap.moduleCodeToDeviceMap.get(data.getDeviceCode()+ SysConstant.SPOT + (data.getModuleCode()!=null?data.getModuleCode():"def"));
        if(emsDevice==null){
            //没找到设备，返回
            return;
        }
        //这里插入一个判断逻辑,是否是保护事件/SOE事件
        EmsProtectSoePidConfig pidConfig = EMSStaticMap.protectSoePidConfigMap.get(data.getEventPid());
        if(pidConfig == null){
            return;
        }
        protectAndSoeEventService.dealWithProtectAndSoeEvent(data,emsDevice,pidConfig);
    }
}
